package com.cn.wanxi.service.impl;

import com.cn.wanxi.dao.UserDao;
import com.cn.wanxi.dao.impl.UserImpl;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {


    /**
     * 服务逻辑层 ---就是封装结果
     * 调用dao
     *
     * @param userModel
     * @return
     */
    @Override
    public ResultModel add(UserModel userModel) {
        UserDao userDao = new UserImpl();
        ResultModel resultModel = new ResultModel();
        int count = userDao.add(userModel);
        if (count > 0) {
            resultModel.setCode(1);
            resultModel.setData(count);
            resultModel.setMessage("增加成功");
//            resultModel.setTotal(1);
        } else {
            resultModel.setCode(0);
            resultModel.setData(count);
            resultModel.setMessage("增加失败");
//            resultModel.setTotal(0);
        }
        return resultModel;
    }

    @Override
    public ResultModel update(UserModel userModel) {
        UserDao userDao = new UserImpl();
        ResultModel resultModel = new ResultModel();
        int count = userDao.update(userModel);
        if (count > 0) {
            resultModel.setCode(1);
            resultModel.setData(count);
            resultModel.setMessage("编辑成功");
//            resultModel.setTotal(1);
        } else {
            resultModel.setCode(0);
            resultModel.setData(count);
            resultModel.setMessage("编辑失败");
//            resultModel.setTotal(0);
        }
        return resultModel;
    }

    @Override
    public List<UserModel> findAll() {
        return null;
    }

    @Override
    public UserModel findById(int i) {
        return null;
    }
}
